package com.hb.core.pojo.project.file.mapper;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hb.core.pojo.project.file.dto.BidFileInfoDTO;
import com.hb.core.pojo.project.file.entity.BidFileInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 招标文件 Mapper 接口
 * </p>
 *
 * @author zhongdl
 * @since 2021-09-16
 */
public interface BidFileInfoMapper extends BaseMapper<BidFileInfo> {

    @Select("SELECT " +
            " GROUP_CONCAT(sectionId) AS sectionIdS," +
            " GROUP_CONCAT(sectionCode) AS sectionCodeS," +
            " auditStatus," +
            " fileId," +
            " biddingDocumentDignaturePdf " +
            " from (" +
            " SELECT " +
            " tbs.id as sectionId," +
            " tbs.file_id as fileId," +
            " tbs.section_name as sectionName," +
            " tbfi.audit_status as auditStatus," +
            " tbfi.bidding_document_signature_pdf as biddingDocumentDignaturePdf," +
            " tbs.section_code AS sectionCode" +
            " from " +
            " trade_bid_file_info tbfi " +
            " left join trade_bid_section tbs on tbfi.id = tbs.file_id" +
            " where tbs.project_id = #{projectId}" +
            " ) tem GROUP BY fileId,auditStatus,biddingDocumentDignaturePdf")
    List<JSONObject> findBidFileInfoListByProjectId(@Param("projectId") Long projectId);

    @Select("SELECT" +
            " tbfi.release_flag" +
            " FROM" +
            " trade_bid_file_info tbfi" +
            " LEFT JOIN trade_bid_section tbs ON tbs.file_id = tbfi.id" +
            " WHERE" +
            " tbs.id = #{sectionId}")
    Integer findBidFileInfoTypeBySectionId(@Param("sectionId") Long sectionId);


    /**
     * 查询指定项目ID的招标文件列表
     *
     * @param projectId
     * @return
     * @update zhaojk
     * @deprecated 原型设计改动, 改为使用招标文件表中projectId直接查询
     */
    @Select("select * from trade_bid_file_info n where n.id in " +
            "(select bs.file_id from trade_bid_section bs where bs.project_id=#{projectId})")
    @Deprecated
    Page<BidFileInfo> pageFilesByProjectId(Page<BidFileInfo> pages, @Param("projectId") Long projectId);

}
